import service from "./index";

/**
 * 登录
 */
export function login(data) {
  return service({
    url: "/user/login",
    method: "POST",
    data: data,
  });
}

/**
 * 注册
 */
export function register(data) {
  return service({
    url: "/user/register",
    method: "POST",
    data: data,
  });
}

/**
 * 分页查询用户信息
 */
export function pageList(pageInfo, user) {
  const params = {
    pageNum: pageInfo.pageNum,
    pageSize: pageInfo.pageSize,
    name: user.name,
    phone: user.phone,
    userName: user.userName,
    pos: user.pos,
    email: user.email,
  };
  return service({
    url: "/user/pageList",
    method: "GET",
    params: params,
  });
}

/**
 * 获取用户信息
 */
export function info() {
  return service({
    url: "/user/info",
    method: "GET",
  });
}

/**
 * 根据用户id删除信息
 */
export function deleteById(id) {
  return service({
    url: `/user/deleteById/${id}`,
    method: "DELETE",
  });
}

/**
 * 根据用户id修改
 */
export function updateById(user) {
  return service({
    url: "/user/updateById",
    method: "PUT",
    data: user,
  });
}

/**
 * 修改密码
 */
export function changePassword(oldPwd, newPwd) {
  return service({
    url: "/user/changePassword",
    params: { oldPwd, newPwd },
    method: "PUT",
  });
}

/**
 * 充值
 */
export function recharge(id, balance) {
  return service({
    url: "/user/recharge",
    method: "PUT",
    data: {
      id: id,
      balance: balance,
    },
  });
}

/**
 * 根据用户id查询用户信息
 */
export function getUserById(userId) {
  return service({
    url: `/user/getUserById/${userId}`,
    method: "GET",
  });
}
